package com.atguigu.java;
class Windows1 extends Thread{
    private static int ticket=100;
//    static Object object=new Object();

    @Override
    public void run() {
        while(true) {
            show();
//            synchronized (object) {

            }

    }
    public static synchronized void show(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (ticket > 0) {
            System.out.println(Thread.currentThread().getName() + ":卖票,票号为:" + ticket);
            ticket--;

        }
    }
}

public class WindowTest3 {
    public static void main(String[] args) {
        Windows1 t1 = new Windows1();
        Windows1 t2 = new Windows1();
        Windows1 t3 = new Windows1();
        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");
        t1.start();
        t2.start();
        t3.start();


    }
}
